﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TvGuide.UI.Models;
using TVGuide.DataAccess.Repository;
using TVGuide.DataAccess.Common;
using TVGuide.Parser;



namespace TvGuide.UI.Controllers
{
    public class HomeController : Controller
    {
        private int lang = 1;
        //
        // GET: Home/

        //public ActionResult Home()
        //{
        //    return View();
        //}
        [HttpGet]
        public ActionResult Home(int? ch, int? id, int? lng)
        {
            ViewData["Runing"] = false;
            if (ch == null)
            {
                return NowRuning(ch, id, lng);
            }
            int? lineindex=null;
            if (lng != null)
                this.lang = (int)lng;

            if (id > 10)
               lineindex = ProgramData.ParseParam(ref id);

            ViewData["selch"] = ch;
            ViewData["selday"] = id;
            ViewData["lng"] = this.lang;
            ProgramData PrData = new ProgramData(this.lang);
            PrData.MakeingWeekDays();
            PrData.ChannelsList();
            PrData.ProgramsList(ProgramData.GetPrDate(ref id), (int)ch,lineindex);
            PrData.ChID = (int)ch;
            PrData.WeekDayID = (int)id;

            return View(PrData);
        }

        public ActionResult NowRuning(int? ch, int? id, int? lng)
        {
            ViewData["Runing"] = true;
            ProgramData PrData = new ProgramData(this.lang);
            PrData.MakeingWeekDays();
            PrData.ChannelsList();
            PrData.NowRuning(DateTime.Now.AddHours(12));
            ViewData["selch"] = 10;
            ViewData["selday"] = 1;
            ViewData["lng"] = this.lang;
            PrData.ChID = 10;
            PrData.WeekDayID = 1;

            return View(PrData);
        }

        public JsonResult GetRuning(int? ch, int? id, int? lng)
        {
            ViewData["Runing"] = true;
            if (lng != null)
                this.lang = (int)lng;
            //ViewData["selch"] = 10;
            //ViewData["selday"] = 1;
            ViewData["lng"] = this.lang;
            ProgramData PrData = new ProgramData(this.lang);
            PrData.NowRuning(ProgramData.SetOnAirDate(ch));
          //  PrData.ChID = (int)ch;
            PrData.WeekDayID = (int)id;
            return Json(PrData);
        }

        public JsonResult GetProg(int? ch, int? id, int? lng)
        {
            ViewData["Runing"] = false;
            if (lng != null)
                this.lang = (int)lng;
            ViewData["selch"] = ch;
            ViewData["selday"] = id;
            ViewData["lng"] = this.lang;
            ProgramData PrData = new ProgramData(this.lang);
            PrData.ProgramsList(ProgramData.GetPrDate(ref id), (int)ch,null);
            PrData.ChID = (int)ch;
            PrData.WeekDayID = (int)id;
            return Json(PrData);
        }

        public ActionResult Do()
        {
            MainProgram.EterParseForWeek();
            MainProgram.NTVParseForWeek();
            MainProgram.ParseForWeek();

            return View();
        }
        public ActionResult MoveCatUpdates()
        {
            TVGuide.DataAccess.Utilsities.moveCatProgsToPrograms();             
            return View();
        }
    }
}
